from app import app
from extensions import db
from models import User, Coach, Course, Activity, Post
from werkzeug.security import generate_password_hash
from datetime import datetime, timedelta
import os

def init_db():
    with app.app_context():
        # 创建所有表
        db.create_all()
        
        # 检查是否已有数据
        if User.query.count() > 0:
            print("数据库已初始化，跳过")
            return
        
        # 创建管理员账户
        admin = User.query.filter_by(username='admin').first()
        if not admin:
            admin = User(
                username='admin',
                email='admin@wandaodiving.com',
                phone='13800138000',
                password_hash=generate_password_hash('admin123'),
                is_admin=True,
                created_at=datetime.utcnow()
            )
            db.session.add(admin)
        
        # ... 其他初始化代码 ...
        
        db.session.commit()
        print("数据库初始化完成")

if __name__ == '__main__':
    init_db() 